<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function Father(uname, age) {
            this.uname = uname;
            this.age = age;
        }
        Father.prototype.sing = function() {
            console.log("我会唱歌");
        }

        function Son(uname, age) {
            Father.call(this, uname, age);
        }
        // 这种赋值操作相当于把父原型对象的地址给了子原型对象，当子原型对象做了修改时，父原型对象也会修改
        //Son.prototype = Father.prototype;//这种写法是错误的

        // new Father() 创建一个Father实例对象，Father实例对象里面的对象原型__proto__指向Father原型对象
        // Son原型对象就继承了Father原型对象里面的sing方法
        Son.prototype = new Father(); //但是Son原型对象的constructor指向了Father构造函数
        // 利用对象的形式会修改原型对象，别忘了利用constructor指回原来的构造函数
        Son.prototype.constructor = Son;
        Son.prototype.exam = function() {
            console.log("孩子要考试");
        }
        var son = new Son("刘德华", 18);
        console.log(son);
        console.log(Son.prototype);
        console.log(Father.prototype); //不会影响Father原型对象
        console.log(Son.prototype.constructor);
    </script>
</body>

</html>